package com.dataart.productshop.service.impl;

import com.dataart.productshop.dao.FileInfoDao;
import com.dataart.productshop.model.FileInfo;
import com.dataart.productshop.model.Type;
import com.dataart.productshop.service.FileInfoManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("fileInfoManager")
@Transactional
public class FileInfoManagerImpl extends BaseManagerImpl<FileInfo> implements FileInfoManager{



	public void setFileInfoDao(FileInfoDao fileInfoDao) {
		this.fileInfoDao = fileInfoDao;
		setBaseDao(fileInfoDao);
	}

	@Override
	public List<FileInfo> getByDownloads(int from, int amount) {
		return fileInfoDao.getByDownloads(from, amount);
		
	}

    @Override
    public FileInfo getByIdEager(Long id) {
        FileInfo file = fileInfoDao.getById(id);
        file.getPictures().size();
        return file;
    }

    @Override
	public List<FileInfo> getFirstFive() {
		return fileInfoDao.getByDownloads(0, 5);
	}

	@Override
	public void saveFileInfo(FileInfo input) {
		fileInfoDao.save(input);
		
	}

	@Override
	public List<FileInfo> getByType(Type type) {
		return fileInfoDao.getByType(type);
	}

	@Override
	public List<FileInfo> getByType(Type type, int from, int amount) {
		return fileInfoDao.getByType(type, from, amount);
	}

	@Override
	public List<FileInfo> getNextTenByType(Type type, int from) {
		return fileInfoDao.getByType(type, from, 10);
	}
}
